Skip to contentSkip to conversation

Change in openvpn[master]: Win32: Make interface index DWORD consistently

Openvpn-devel In review flichtenheld (Code Review) 2 participants 8 messages Feb 12 – Mar 11 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1770904306000.I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email

to review the following change.

Change subject: Win32: Make interface index DWORD consistently
......................................................................

Win32: Make interface index DWORD consistently

Previously we had a weird mix of int and DWORD. But the Win32 APIs seem to be consistent (they have different names, but NET_IFINDEX is ULONG is DWORD). So use that.

Change-Id I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81

---
M include/openvpn-msg.h
M src/openvpn/dns.c
M src/openvpn/route.c
M src/openvpn/tun.c
M src/openvpn/tun.h
M src/openvpn/win32.c
M src/openvpnserv/interactive.c

7 files changed, 48 insertions(+), 57 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/19/1519/1

include/openvpn-msg.h +2 -1
index a0cec53..34f50c8 100644
@@ -66,7 +66,8 @@
 
 typedef struct
 {
-    int index;
+#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
+    DWORD index;
     char name[256];
 } interface_t;
 
src/openvpn/dns.c +3 -2
index fd388ce..2137a75 100644
@@ -468,9 +468,10 @@
     make_domain_list("dns search domains", search_domains, false, nrpt.search_domains,
                      sizeof(nrpt.search_domains));
 
-    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), nrpt.resolve_domains[0] != 0 ? ", resolve domains" : "",
-        nrpt.search_domains[0] != 0 ? ", search domains" : "", nrpt.iface.name, nrpt.iface.index);
+        nrpt.search_domains[0] != 0 ? ", search domains" : "",
+        nrpt.iface.name, nrpt.iface.index);
 
     send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS");
 }
src/openvpn/route.c +20 -29

123 lines not on this page · raw message

src/openvpn/tun.c +13 -13
index ad77117..5c1ba25 100644
@@ -158,7 +158,7 @@
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_WARN, "TUN: %s address failed using service: %s [status=%u if_index=%d]",
+        msg(M_WARN, "TUN: %s address failed using service: %s [status=%u if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             addr.iface.index);
         goto out;
@@ -220,7 +220,7 @@
         strncpy(dns.domains + dstlen, o->domain_search_list[i], srclen + 1);
     }
 
-    msg(D_LOW, "%s DNS domains on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s DNS domains on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), dns.iface.name, dns.iface.index);
     if (!send_msg_iservice(o->msg_channel, &dns, sizeof(dns), &ack, "TUN"))
     {
@@ -289,7 +289,7 @@
         }
     }
 
-    msg(D_LOW, "%s %s dns servers on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s %s dns servers on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), ip_proto_name, dns.iface.name, dns.iface.index);
 
     if (!send_msg_iservice(pipe, &dns, sizeof(dns), &ack, "TUN"))
@@ -346,7 +346,7 @@
         wins.addr[i].ipv4.s_addr = htonl(tt->options.wins[i]);
     }
 
-    msg(D_LOW, "%s WINS servers on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s WINS servers on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), wins.iface.name, wins.iface.index);
 
     if (!send_msg_iservice(pipe, &wins, sizeof(wins), &ack, "TUN"))
@@ -398,13 +398,13 @@
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%d]",
+        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%lu]",
             family_name, strerror_win32(ack.error_number, &gc), ack.error_number,
             mtu_msg.iface.index);
     }
     else
     {
-        msg(M_INFO, "%s MTU set to %d on interface %d using service", family_name, mtu,
+        msg(M_INFO, "%s MTU set to %d on interface %lu using service", family_name, mtu,
             mtu_msg.iface.index);
         ret = true;
     }
@@ -4456,8 +4456,8 @@
         list = list->Next;
     }
 
-    dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=%s nm=%s index=%d count=%d metric=%d",
-         print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, &gc), (int)ret,
+    dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=%s nm=%s index=%lu count=%d metric=%d",
+         print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, &gc), ret,
          count ? *count : -1, lowest_metric);
 
     if (ret == TUN_ADAPTER_INDEX_INVALID && count)
@@ -4634,7 +4634,7 @@
 show_adapter(msglvl_t msglevel, const IP_ADAPTER_INFO *a, struct gc_arena *gc)
 {
     msg(msglevel, "%s", a->Description);
-    msg(msglevel, "  Index = %d", (int)a->Index);
+    msg(msglevel, "  Index = %lu", a->Index);
     msg(msglevel, "  GUID = %s", a->AdapterName);
     msg(msglevel, "  IP = %s", format_ip_addr_string(&a->IpAddressList, gc));
     msg(msglevel, "  MAC = %s", format_hex_ex(a->Address, a->AddressLength, 0, 1, ":", gc));
@@ -5215,12 +5215,12 @@
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_NONFATAL, "TUN: enabling dhcp using service failed: %s [status=%u if_index=%d]",
+        msg(M_NONFATAL, "TUN: enabling dhcp using service failed: %s [status=%u if_index=%lu]",
             strerror_win32(ack.error_number, &gc), ack.error_number, dhcp.iface.index);
     }
     else
     {
-        msg(M_INFO, "DHCP enabled on interface %d using service", dhcp.iface.index);
+        msg(M_INFO, "DHCP enabled on interface %lu using service", dhcp.iface.index);
         ret = true;
     }
 
@@ -5510,7 +5510,7 @@
     /* flush arp cache */
     if (tt->backend_driver == WINDOWS_DRIVER_TAP_WINDOWS6 && index != TUN_ADAPTER_INDEX_INVALID)
     {
-        DWORD status = -1;
+        DWORD status = (DWORD)-1;
 
         if (tt->options.msg_channel)
         {
@@ -5534,7 +5534,7 @@
         {
             msg(M_INFO, "Successful ARP Flush on interface [%lu] %s", index, device_guid);
         }
-        else if (status != -1)
+        else if (status != (DWORD)-1)
         {
             msg(D_TUNTAP_INFO,
                 "NOTE: FlushIpNetTable failed on interface [%lu] %s (status=%lu) : %s", index,
src/openvpn/tun.h +1 -3
index a226e37..388f5b7 100644
@@ -61,8 +61,6 @@
 
 #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST)
 
-#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
-
 /* time constants for --ip-win32 adaptive */
 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
 #define IPW32_SET_ADAPTIVE_TRY_NETSH    20
@@ -230,7 +228,7 @@
     in_addr_t adapter_netmask;
 
     /* Windows adapter index for TAP-Windows adapter,
-     * ~0 if undefined */
+     * TUN_ADAPTER_INDEX_INVALID if undefined */
     DWORD adapter_index;
 
     int standby_iter;
src/openvpn/win32.c +1 -1
index ac449fd..b2a7331 100644
@@ -1185,7 +1185,7 @@
     if (ack.error_number != NO_ERROR)
     {
         msg(M_WARN,
-            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%d]",
+            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             data.iface.index);
         goto out;
src/openvpnserv/interactive.c +8 -8
index 09c709e..b50aeb3 100644
@@ -96,7 +96,7 @@
 typedef struct
 {
     HANDLE engine;
-    int index;
+    DWORD index;
     int metric_v4;
     int metric_v6;
 } wfp_block_data_t;
@@ -584,7 +584,7 @@
     addr_row->Address = sockaddr_inet(msg->family, &msg->address);
     addr_row->OnLinkPrefixLength = (UINT8)msg->prefix_len;
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         addr_row->InterfaceIndex = msg->iface.index;
     }
@@ -667,7 +667,7 @@
     fwd_row->DestinationPrefix.PrefixLength = (UINT8)msg->prefix_len;
     fwd_row->NextHop = sockaddr_inet(msg->family, &msg->gateway);
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         fwd_row->InterfaceIndex = msg->iface.index;
     }
@@ -1010,7 +1010,7 @@
  * if action = "set" then "static" is added before $addr
  */
 static DWORD
-netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr)
+netsh_wins_cmd(const wchar_t *action, DWORD if_index, const wchar_t *addr)
 {
     DWORD err = 0;
     int timeout = 30000; /* in msec */
@@ -1036,7 +1036,7 @@
     /* cmd template:
      * netsh interface ip $action wins $if_name $static $addr
      */
-    const wchar_t *fmt = L"netsh interface ip %ls wins %d %ls %ls";
+    const wchar_t *fmt = L"netsh interface ip %ls wins %lu %ls %ls";
 
     /* max cmdline length in wchars -- include room for worst case and some */
     size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr)
@@ -2984,7 +2984,7 @@
          */
     }
 
-    int *if_index = malloc(sizeof(msg->iface.index));
+    PDWORD if_index = malloc(sizeof(msg->iface.index));
     if (if_index)
     {
         *if_index = msg->iface.index;
@@ -3017,7 +3017,7 @@
     /* cmd template:
      * netsh interface ipv4 set address name=$if_index source=dhcp
      */
-    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%d\" source=dhcp";
+    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%lu\" source=dhcp";
 
     /* max cmdline length in wchars -- include room for if index:
      * 10 chars for 32 bit int in decimal and +1 for NUL
@@ -3250,7 +3250,7 @@
                     break;
 
                 case undo_wins:
-                    netsh_wins_cmd(L"delete", *(int *)item->data, NULL);
+                    netsh_wins_cmd(L"delete", *(PDWORD)item->data, NULL);
                     break;
 
                 case wfp_block:

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81
Gerrit-Change-Number: 1519
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email

to look at the new patch set (#2).

Change subject: Win32: Make interface index DWORD consistently
......................................................................

Win32: Make interface index DWORD consistently

Previously we had a weird mix of int and DWORD. But the Win32 APIs seem to be consistent (they have different names, but NET_IFINDEX is ULONG is DWORD). So use that.

Note that this fixes some smaller issues in surrounding code that are not strictly related but were found while scanning the code. Mostly about needlessly converting all DWORD values to int for printf().

Change-Id I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81

---
M include/openvpn-msg.h
M src/openvpn/dns.c
M src/openvpn/route.c
M src/openvpn/tun.c
M src/openvpn/tun.h
M src/openvpn/win32.c
M src/openvpnserv/interactive.c

7 files changed, 50 insertions(+), 60 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/19/1519/2

include/openvpn-msg.h +2 -1
index a0cec53..34f50c8 100644
@@ -66,7 +66,8 @@
 
 typedef struct
 {
-    int index;
+#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
+    DWORD index;
     char name[256];
 } interface_t;
 
src/openvpn/dns.c +3 -2
index fd388ce..2137a75 100644
@@ -468,9 +468,10 @@
     make_domain_list("dns search domains", search_domains, false, nrpt.search_domains,
                      sizeof(nrpt.search_domains));
 
-    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), nrpt.resolve_domains[0] != 0 ? ", resolve domains" : "",
-        nrpt.search_domains[0] != 0 ? ", search domains" : "", nrpt.iface.name, nrpt.iface.index);
+        nrpt.search_domains[0] != 0 ? ", search domains" : "",
+        nrpt.iface.name, nrpt.iface.index);
 
     send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS");
 }
src/openvpn/route.c +22 -32

137 lines not on this page · raw message

src/openvpn/tun.c +13 -13
index ad77117..5c1ba25 100644
@@ -158,7 +158,7 @@
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_WARN, "TUN: %s address failed using service: %s [status=%u if_index=%d]",
+        msg(M_WARN, "TUN: %s address failed using service: %s [status=%u if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             addr.iface.index);
         goto out;
@@ -220,7 +220,7 @@
         strncpy(dns.domains + dstlen, o->domain_search_list[i], srclen + 1);
     }
 
-    msg(D_LOW, "%s DNS domains on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s DNS domains on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), dns.iface.name, dns.iface.index);
     if (!send_msg_iservice(o->msg_channel, &dns, sizeof(dns), &ack, "TUN"))
     {
@@ -289,7 +289,7 @@
         }
     }
 
-    msg(D_LOW, "%s %s dns servers on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s %s dns servers on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), ip_proto_name, dns.iface.name, dns.iface.index);
 
     if (!send_msg_iservice(pipe, &dns, sizeof(dns), &ack, "TUN"))
@@ -346,7 +346,7 @@
         wins.addr[i].ipv4.s_addr = htonl(tt->options.wins[i]);
     }
 
-    msg(D_LOW, "%s WINS servers on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s WINS servers on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), wins.iface.name, wins.iface.index);
 
     if (!send_msg_iservice(pipe, &wins, sizeof(wins), &ack, "TUN"))
@@ -398,13 +398,13 @@
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%d]",
+        msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [status=%u if_index=%lu]",
             family_name, strerror_win32(ack.error_number, &gc), ack.error_number,
             mtu_msg.iface.index);
     }
     else
     {
-        msg(M_INFO, "%s MTU set to %d on interface %d using service", family_name, mtu,
+        msg(M_INFO, "%s MTU set to %d on interface %lu using service", family_name, mtu,
             mtu_msg.iface.index);
         ret = true;
     }
@@ -4456,8 +4456,8 @@
         list = list->Next;
     }
 
-    dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=%s nm=%s index=%d count=%d metric=%d",
-         print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, &gc), (int)ret,
+    dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=%s nm=%s index=%lu count=%d metric=%d",
+         print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, &gc), ret,
          count ? *count : -1, lowest_metric);
 
     if (ret == TUN_ADAPTER_INDEX_INVALID && count)
@@ -4634,7 +4634,7 @@
 show_adapter(msglvl_t msglevel, const IP_ADAPTER_INFO *a, struct gc_arena *gc)
 {
     msg(msglevel, "%s", a->Description);
-    msg(msglevel, "  Index = %d", (int)a->Index);
+    msg(msglevel, "  Index = %lu", a->Index);
     msg(msglevel, "  GUID = %s", a->AdapterName);
     msg(msglevel, "  IP = %s", format_ip_addr_string(&a->IpAddressList, gc));
     msg(msglevel, "  MAC = %s", format_hex_ex(a->Address, a->AddressLength, 0, 1, ":", gc));
@@ -5215,12 +5215,12 @@
 
     if (ack.error_number != NO_ERROR)
     {
-        msg(M_NONFATAL, "TUN: enabling dhcp using service failed: %s [status=%u if_index=%d]",
+        msg(M_NONFATAL, "TUN: enabling dhcp using service failed: %s [status=%u if_index=%lu]",
             strerror_win32(ack.error_number, &gc), ack.error_number, dhcp.iface.index);
     }
     else
     {
-        msg(M_INFO, "DHCP enabled on interface %d using service", dhcp.iface.index);
+        msg(M_INFO, "DHCP enabled on interface %lu using service", dhcp.iface.index);
         ret = true;
     }
 
@@ -5510,7 +5510,7 @@
     /* flush arp cache */
     if (tt->backend_driver == WINDOWS_DRIVER_TAP_WINDOWS6 && index != TUN_ADAPTER_INDEX_INVALID)
     {
-        DWORD status = -1;
+        DWORD status = (DWORD)-1;
 
         if (tt->options.msg_channel)
         {
@@ -5534,7 +5534,7 @@
         {
             msg(M_INFO, "Successful ARP Flush on interface [%lu] %s", index, device_guid);
         }
-        else if (status != -1)
+        else if (status != (DWORD)-1)
         {
             msg(D_TUNTAP_INFO,
                 "NOTE: FlushIpNetTable failed on interface [%lu] %s (status=%lu) : %s", index,
src/openvpn/tun.h +1 -3
index a226e37..388f5b7 100644
@@ -61,8 +61,6 @@
 
 #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST)
 
-#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
-
 /* time constants for --ip-win32 adaptive */
 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
 #define IPW32_SET_ADAPTIVE_TRY_NETSH    20
@@ -230,7 +228,7 @@
     in_addr_t adapter_netmask;
 
     /* Windows adapter index for TAP-Windows adapter,
-     * ~0 if undefined */
+     * TUN_ADAPTER_INDEX_INVALID if undefined */
     DWORD adapter_index;
 
     int standby_iter;
src/openvpn/win32.c +1 -1
index ac449fd..b2a7331 100644
@@ -1185,7 +1185,7 @@
     if (ack.error_number != NO_ERROR)
     {
         msg(M_WARN,
-            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%d]",
+            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             data.iface.index);
         goto out;
src/openvpnserv/interactive.c +8 -8
index 09c709e..b50aeb3 100644
@@ -96,7 +96,7 @@
 typedef struct
 {
     HANDLE engine;
-    int index;
+    DWORD index;
     int metric_v4;
     int metric_v6;
 } wfp_block_data_t;
@@ -584,7 +584,7 @@
     addr_row->Address = sockaddr_inet(msg->family, &msg->address);
     addr_row->OnLinkPrefixLength = (UINT8)msg->prefix_len;
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         addr_row->InterfaceIndex = msg->iface.index;
     }
@@ -667,7 +667,7 @@
     fwd_row->DestinationPrefix.PrefixLength = (UINT8)msg->prefix_len;
     fwd_row->NextHop = sockaddr_inet(msg->family, &msg->gateway);
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         fwd_row->InterfaceIndex = msg->iface.index;
     }
@@ -1010,7 +1010,7 @@
  * if action = "set" then "static" is added before $addr
  */
 static DWORD
-netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr)
+netsh_wins_cmd(const wchar_t *action, DWORD if_index, const wchar_t *addr)
 {
     DWORD err = 0;
     int timeout = 30000; /* in msec */
@@ -1036,7 +1036,7 @@
     /* cmd template:
      * netsh interface ip $action wins $if_name $static $addr
      */
-    const wchar_t *fmt = L"netsh interface ip %ls wins %d %ls %ls";
+    const wchar_t *fmt = L"netsh interface ip %ls wins %lu %ls %ls";
 
     /* max cmdline length in wchars -- include room for worst case and some */
     size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr)
@@ -2984,7 +2984,7 @@
          */
     }
 
-    int *if_index = malloc(sizeof(msg->iface.index));
+    PDWORD if_index = malloc(sizeof(msg->iface.index));
     if (if_index)
     {
         *if_index = msg->iface.index;
@@ -3017,7 +3017,7 @@
     /* cmd template:
      * netsh interface ipv4 set address name=$if_index source=dhcp
      */
-    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%d\" source=dhcp";
+    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%lu\" source=dhcp";
 
     /* max cmdline length in wchars -- include room for if index:
      * 10 chars for 32 bit int in decimal and +1 for NUL
@@ -3250,7 +3250,7 @@
                     break;
 
                 case undo_wins:
-                    netsh_wins_cmd(L"delete", *(int *)item->data, NULL);
+                    netsh_wins_cmd(L"delete", *(PDWORD)item->data, NULL);
                     break;
 
                 case wfp_block:

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81
Gerrit-Change-Number: 1519
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email

to look at the new patch set (#3).

Change subject: Win32: Make interface index DWORD consistently
......................................................................

Win32: Make interface index DWORD consistently

Previously we had a weird mix of int and DWORD. But the Win32 APIs seem to be consistent (they have different names, but NET_IFINDEX is ULONG is DWORD). So use that.

Note that this fixes some smaller issues in surrounding code that are not strictly related but were found while scanning the code. Mostly about needlessly converting all DWORD values to int for printf().

Change-Id I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81

---
M include/openvpn-msg.h
M src/openvpn/dns.c
M src/openvpn/route.c
M src/openvpn/tun.c
M src/openvpn/tun.h
M src/openvpn/win32.c
M src/openvpnserv/interactive.c

7 files changed, 78 insertions(+), 87 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/19/1519/3

include/openvpn-msg.h +2 -1
index a0cec53..34f50c8 100644
@@ -66,7 +66,8 @@
 
 typedef struct
 {
-    int index;
+#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
+    DWORD index;
     char name[256];
 } interface_t;
 
src/openvpn/dns.c +3 -2
index fd388ce..2137a75 100644
@@ -468,9 +468,10 @@
     make_domain_list("dns search domains", search_domains, false, nrpt.search_domains,
                      sizeof(nrpt.search_domains));
 
-    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), nrpt.resolve_domains[0] != 0 ? ", resolve domains" : "",
-        nrpt.search_domains[0] != 0 ? ", search domains" : "", nrpt.iface.name, nrpt.iface.index);
+        nrpt.search_domains[0] != 0 ? ", search domains" : "",
+        nrpt.iface.name, nrpt.iface.index);
 
     send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS");
 }
src/openvpn/route.c +30 -40

177 lines not on this page · raw message

src/openvpn/tun.c +33 -32

219 lines not on this page · raw message

src/openvpn/tun.h +1 -3
index a226e37..388f5b7 100644
@@ -61,8 +61,6 @@
 
 #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST)
 
-#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
-
 /* time constants for --ip-win32 adaptive */
 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
 #define IPW32_SET_ADAPTIVE_TRY_NETSH    20
@@ -230,7 +228,7 @@
     in_addr_t adapter_netmask;
 
     /* Windows adapter index for TAP-Windows adapter,
-     * ~0 if undefined */
+     * TUN_ADAPTER_INDEX_INVALID if undefined */
     DWORD adapter_index;
 
     int standby_iter;
src/openvpn/win32.c +1 -1
index ac449fd..b2a7331 100644
@@ -1185,7 +1185,7 @@
     if (ack.error_number != NO_ERROR)
     {
         msg(M_WARN,
-            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%d]",
+            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             data.iface.index);
         goto out;
src/openvpnserv/interactive.c +8 -8
index 09c709e..b50aeb3 100644
@@ -96,7 +96,7 @@
 typedef struct
 {
     HANDLE engine;
-    int index;
+    DWORD index;
     int metric_v4;
     int metric_v6;
 } wfp_block_data_t;
@@ -584,7 +584,7 @@
     addr_row->Address = sockaddr_inet(msg->family, &msg->address);
     addr_row->OnLinkPrefixLength = (UINT8)msg->prefix_len;
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         addr_row->InterfaceIndex = msg->iface.index;
     }
@@ -667,7 +667,7 @@
     fwd_row->DestinationPrefix.PrefixLength = (UINT8)msg->prefix_len;
     fwd_row->NextHop = sockaddr_inet(msg->family, &msg->gateway);
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         fwd_row->InterfaceIndex = msg->iface.index;
     }
@@ -1010,7 +1010,7 @@
  * if action = "set" then "static" is added before $addr
  */
 static DWORD
-netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr)
+netsh_wins_cmd(const wchar_t *action, DWORD if_index, const wchar_t *addr)
 {
     DWORD err = 0;
     int timeout = 30000; /* in msec */
@@ -1036,7 +1036,7 @@
     /* cmd template:
      * netsh interface ip $action wins $if_name $static $addr
      */
-    const wchar_t *fmt = L"netsh interface ip %ls wins %d %ls %ls";
+    const wchar_t *fmt = L"netsh interface ip %ls wins %lu %ls %ls";
 
     /* max cmdline length in wchars -- include room for worst case and some */
     size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr)
@@ -2984,7 +2984,7 @@
          */
     }
 
-    int *if_index = malloc(sizeof(msg->iface.index));
+    PDWORD if_index = malloc(sizeof(msg->iface.index));
     if (if_index)
     {
         *if_index = msg->iface.index;
@@ -3017,7 +3017,7 @@
     /* cmd template:
      * netsh interface ipv4 set address name=$if_index source=dhcp
      */
-    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%d\" source=dhcp";
+    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%lu\" source=dhcp";
 
     /* max cmdline length in wchars -- include room for if index:
      * 10 chars for 32 bit int in decimal and +1 for NUL
@@ -3250,7 +3250,7 @@
                     break;
 
                 case undo_wins:
-                    netsh_wins_cmd(L"delete", *(int *)item->data, NULL);
+                    netsh_wins_cmd(L"delete", *(PDWORD)item->data, NULL);
                     break;
 
                 case wfp_block:

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81
Gerrit-Change-Number: 1519
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email )

Change subject: Win32: Make interface index DWORD consistently
......................................................................

Patch Set 6: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81
Gerrit-Change-Number: 1519
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Mar 2026 16:38:27 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#5 lore raw

PATCH v6 1/1 Win32: Make interface index DWORD consistently

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

Previously we had a weird mix of int and DWORD. But the Win32 APIs seem to be consistent (they have different names, but NET_IFINDEX is ULONG is DWORD). So use that.

Note that this fixes some smaller issues in surrounding code that are not strictly related but were found while scanning the code. Mostly about needlessly converting all DWORD values to int for printf().

Change-Id I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1519
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1519
This mail reflects revision 6 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

include/openvpn-msg.h +2 -1
index a0cec53..34f50c8 100644
@@ -66,7 +66,8 @@
 
 typedef struct
 {
-    int index;
+#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
+    DWORD index;
     char name[256];
 } interface_t;
 
src/openvpn/dns.c +3 -2
index 4a4bb0c..a42d032 100644
@@ -468,9 +468,10 @@
     make_domain_list("dns search domains", search_domains, false, nrpt.search_domains,
                      sizeof(nrpt.search_domains));
 
-    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), nrpt.resolve_domains[0] != 0 ? ", resolve domains" : "",
-        nrpt.search_domains[0] != 0 ? ", search domains" : "", nrpt.iface.name, nrpt.iface.index);
+        nrpt.search_domains[0] != 0 ? ", search domains" : "",
+        nrpt.iface.name, nrpt.iface.index);
 
     send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS");
 }
src/openvpn/route.c +30 -40

177 lines not on this page · raw message

src/openvpn/tun.c +33 -32

219 lines not on this page · raw message

src/openvpn/tun.h +1 -3
index 4d6dfbb..ecb5e88 100644
@@ -61,8 +61,6 @@
 
 #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST)
 
-#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
-
 /* time constants for --ip-win32 adaptive */
 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
 #define IPW32_SET_ADAPTIVE_TRY_NETSH    20
@@ -230,7 +228,7 @@
     in_addr_t adapter_netmask;
 
     /* Windows adapter index for TAP-Windows adapter,
-     * ~0 if undefined */
+     * TUN_ADAPTER_INDEX_INVALID if undefined */
     DWORD adapter_index;
 
     int standby_iter;
src/openvpn/win32.c +1 -1
index ac449fd..b2a7331 100644
@@ -1185,7 +1185,7 @@
     if (ack.error_number != NO_ERROR)
     {
         msg(M_WARN,
-            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%d]",
+            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             data.iface.index);
         goto out;
src/openvpnserv/interactive.c +8 -8
index 09c709e..b50aeb3 100644
@@ -96,7 +96,7 @@
 typedef struct
 {
     HANDLE engine;
-    int index;
+    DWORD index;
     int metric_v4;
     int metric_v6;
 } wfp_block_data_t;
@@ -584,7 +584,7 @@
     addr_row->Address = sockaddr_inet(msg->family, &msg->address);
     addr_row->OnLinkPrefixLength = (UINT8)msg->prefix_len;
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         addr_row->InterfaceIndex = msg->iface.index;
     }
@@ -667,7 +667,7 @@
     fwd_row->DestinationPrefix.PrefixLength = (UINT8)msg->prefix_len;
     fwd_row->NextHop = sockaddr_inet(msg->family, &msg->gateway);
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         fwd_row->InterfaceIndex = msg->iface.index;
     }
@@ -1010,7 +1010,7 @@
  * if action = "set" then "static" is added before $addr
  */
 static DWORD
-netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr)
+netsh_wins_cmd(const wchar_t *action, DWORD if_index, const wchar_t *addr)
 {
     DWORD err = 0;
     int timeout = 30000; /* in msec */
@@ -1036,7 +1036,7 @@
     /* cmd template:
      * netsh interface ip $action wins $if_name $static $addr
      */
-    const wchar_t *fmt = L"netsh interface ip %ls wins %d %ls %ls";
+    const wchar_t *fmt = L"netsh interface ip %ls wins %lu %ls %ls";
 
     /* max cmdline length in wchars -- include room for worst case and some */
     size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr)
@@ -2984,7 +2984,7 @@
          */
     }
 
-    int *if_index = malloc(sizeof(msg->iface.index));
+    PDWORD if_index = malloc(sizeof(msg->iface.index));
     if (if_index)
     {
         *if_index = msg->iface.index;
@@ -3017,7 +3017,7 @@
     /* cmd template:
      * netsh interface ipv4 set address name=$if_index source=dhcp
      */
-    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%d\" source=dhcp";
+    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%lu\" source=dhcp";
 
     /* max cmdline length in wchars -- include room for if index:
      * 10 chars for 32 bit int in decimal and +1 for NUL
@@ -3250,7 +3250,7 @@
                     break;
 
                 case undo_wins:
-                    netsh_wins_cmd(L"delete", *(int *)item->data, NULL);
+                    netsh_wins_cmd(L"delete", *(PDWORD)item->data, NULL);
                     break;
 
                 case wfp_block:
#6 lore raw

[Openvpn-devel] [PATCH applied] Re: Win32: Make interface index DWORD consistently

Patch in itself looks reasonable, and also fixes the -Werror breakage I introduced merging the last one "out of sequence". Sorry for that.

Your patch has been applied to the master branch.

commit 7afd3cf066bfc13b3b01c0845ccf1c35ea640b1d

Author: Frank Lichtenheld
Date:   Wed Mar 11 17:38:45 2026 +0100
     Win32: Make interface index DWORD consistently

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1519
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg36021.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

cron2 has uploaded a new patch set (#7) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.

Change subject: Win32: Make interface index DWORD consistently
......................................................................

Win32: Make interface index DWORD consistently

Previously we had a weird mix of int and DWORD. But the Win32 APIs seem to be consistent (they have different names, but NET_IFINDEX is ULONG is DWORD). So use that.

Note that this fixes some smaller issues in surrounding code that are not strictly related but were found while scanning the code. Mostly about needlessly converting all DWORD values to int for printf().

Change-Id I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1519
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36021.html

---
M include/openvpn-msg.h
M src/openvpn/dns.c
M src/openvpn/route.c
M src/openvpn/tun.c
M src/openvpn/tun.h
M src/openvpn/win32.c
M src/openvpnserv/interactive.c

7 files changed, 78 insertions(+), 87 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/19/1519/7

include/openvpn-msg.h +2 -1
index a0cec53..34f50c8 100644
@@ -66,7 +66,8 @@
 
 typedef struct
 {
-    int index;
+#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
+    DWORD index;
     char name[256];
 } interface_t;
 
src/openvpn/dns.c +3 -2
index 4a4bb0c..a42d032 100644
@@ -468,9 +468,10 @@
     make_domain_list("dns search domains", search_domains, false, nrpt.search_domains,
                      sizeof(nrpt.search_domains));
 
-    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), nrpt.resolve_domains[0] != 0 ? ", resolve domains" : "",
-        nrpt.search_domains[0] != 0 ? ", search domains" : "", nrpt.iface.name, nrpt.iface.index);
+        nrpt.search_domains[0] != 0 ? ", search domains" : "",
+        nrpt.iface.name, nrpt.iface.index);
 
     send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS");
 }
src/openvpn/route.c +30 -40

177 lines not on this page · raw message

src/openvpn/tun.c +33 -32

219 lines not on this page · raw message

src/openvpn/tun.h +1 -3
index 4d6dfbb..ecb5e88 100644
@@ -61,8 +61,6 @@
 
 #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST)
 
-#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
-
 /* time constants for --ip-win32 adaptive */
 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
 #define IPW32_SET_ADAPTIVE_TRY_NETSH    20
@@ -230,7 +228,7 @@
     in_addr_t adapter_netmask;
 
     /* Windows adapter index for TAP-Windows adapter,
-     * ~0 if undefined */
+     * TUN_ADAPTER_INDEX_INVALID if undefined */
     DWORD adapter_index;
 
     int standby_iter;
src/openvpn/win32.c +1 -1
index ac449fd..b2a7331 100644
@@ -1185,7 +1185,7 @@
     if (ack.error_number != NO_ERROR)
     {
         msg(M_WARN,
-            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%d]",
+            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             data.iface.index);
         goto out;
src/openvpnserv/interactive.c +8 -8
index 09c709e..b50aeb3 100644
@@ -96,7 +96,7 @@
 typedef struct
 {
     HANDLE engine;
-    int index;
+    DWORD index;
     int metric_v4;
     int metric_v6;
 } wfp_block_data_t;
@@ -584,7 +584,7 @@
     addr_row->Address = sockaddr_inet(msg->family, &msg->address);
     addr_row->OnLinkPrefixLength = (UINT8)msg->prefix_len;
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         addr_row->InterfaceIndex = msg->iface.index;
     }
@@ -667,7 +667,7 @@
     fwd_row->DestinationPrefix.PrefixLength = (UINT8)msg->prefix_len;
     fwd_row->NextHop = sockaddr_inet(msg->family, &msg->gateway);
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         fwd_row->InterfaceIndex = msg->iface.index;
     }
@@ -1010,7 +1010,7 @@
  * if action = "set" then "static" is added before $addr
  */
 static DWORD
-netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr)
+netsh_wins_cmd(const wchar_t *action, DWORD if_index, const wchar_t *addr)
 {
     DWORD err = 0;
     int timeout = 30000; /* in msec */
@@ -1036,7 +1036,7 @@
     /* cmd template:
      * netsh interface ip $action wins $if_name $static $addr
      */
-    const wchar_t *fmt = L"netsh interface ip %ls wins %d %ls %ls";
+    const wchar_t *fmt = L"netsh interface ip %ls wins %lu %ls %ls";
 
     /* max cmdline length in wchars -- include room for worst case and some */
     size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr)
@@ -2984,7 +2984,7 @@
          */
     }
 
-    int *if_index = malloc(sizeof(msg->iface.index));
+    PDWORD if_index = malloc(sizeof(msg->iface.index));
     if (if_index)
     {
         *if_index = msg->iface.index;
@@ -3017,7 +3017,7 @@
     /* cmd template:
      * netsh interface ipv4 set address name=$if_index source=dhcp
      */
-    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%d\" source=dhcp";
+    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%lu\" source=dhcp";
 
     /* max cmdline length in wchars -- include room for if index:
      * 10 chars for 32 bit int in decimal and +1 for NUL
@@ -3250,7 +3250,7 @@
                     break;
 
                 case undo_wins:
-                    netsh_wins_cmd(L"delete", *(int *)item->data, NULL);
+                    netsh_wins_cmd(L"delete", *(PDWORD)item->data, NULL);
                     break;
 
                 case wfp_block:

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81
Gerrit-Change-Number: 1519
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#8 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email )

Change subject: Win32: Make interface index DWORD consistently
......................................................................

Win32: Make interface index DWORD consistently

Previously we had a weird mix of int and DWORD. But the Win32 APIs seem to be consistent (they have different names, but NET_IFINDEX is ULONG is DWORD). So use that.

Note that this fixes some smaller issues in surrounding code that are not strictly related but were found while scanning the code. Mostly about needlessly converting all DWORD values to int for printf().

Change-Id I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1519
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36021.html

---
M include/openvpn-msg.h
M src/openvpn/dns.c
M src/openvpn/route.c
M src/openvpn/tun.c
M src/openvpn/tun.h
M src/openvpn/win32.c
M src/openvpnserv/interactive.c

7 files changed, 78 insertions(+), 87 deletions(-)
include/openvpn-msg.h +2 -1
index a0cec53..34f50c8 100644
@@ -66,7 +66,8 @@
 
 typedef struct
 {
-    int index;
+#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
+    DWORD index;
     char name[256];
 } interface_t;
 
src/openvpn/dns.c +3 -2
index 4a4bb0c..a42d032 100644
@@ -468,9 +468,10 @@
     make_domain_list("dns search domains", search_domains, false, nrpt.search_domains,
                      sizeof(nrpt.search_domains));
 
-    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %d) using service",
+    msg(D_LOW, "%s NRPT DNS%s%s on '%s' (if_index = %lu) using service",
         (add ? "Setting" : "Deleting"), nrpt.resolve_domains[0] != 0 ? ", resolve domains" : "",
-        nrpt.search_domains[0] != 0 ? ", search domains" : "", nrpt.iface.name, nrpt.iface.index);
+        nrpt.search_domains[0] != 0 ? ", search domains" : "",
+        nrpt.iface.name, nrpt.iface.index);
 
     send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS");
 }
src/openvpn/route.c +30 -40

177 lines not on this page · raw message

src/openvpn/tun.c +33 -32

219 lines not on this page · raw message

src/openvpn/tun.h +1 -3
index 4d6dfbb..ecb5e88 100644
@@ -61,8 +61,6 @@
 
 #if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST)
 
-#define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1)
-
 /* time constants for --ip-win32 adaptive */
 #define IPW32_SET_ADAPTIVE_DELAY_WINDOW 300
 #define IPW32_SET_ADAPTIVE_TRY_NETSH    20
@@ -230,7 +228,7 @@
     in_addr_t adapter_netmask;
 
     /* Windows adapter index for TAP-Windows adapter,
-     * ~0 if undefined */
+     * TUN_ADAPTER_INDEX_INVALID if undefined */
     DWORD adapter_index;
 
     int standby_iter;
src/openvpn/win32.c +1 -1
index ac449fd..b2a7331 100644
@@ -1185,7 +1185,7 @@
     if (ack.error_number != NO_ERROR)
     {
         msg(M_WARN,
-            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%d]",
+            "WFP block: %s block filters using service failed: %s [status=0x%x if_index=%lu]",
             (add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc), ack.error_number,
             data.iface.index);
         goto out;
src/openvpnserv/interactive.c +8 -8
index 09c709e..b50aeb3 100644
@@ -96,7 +96,7 @@
 typedef struct
 {
     HANDLE engine;
-    int index;
+    DWORD index;
     int metric_v4;
     int metric_v6;
 } wfp_block_data_t;
@@ -584,7 +584,7 @@
     addr_row->Address = sockaddr_inet(msg->family, &msg->address);
     addr_row->OnLinkPrefixLength = (UINT8)msg->prefix_len;
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         addr_row->InterfaceIndex = msg->iface.index;
     }
@@ -667,7 +667,7 @@
     fwd_row->DestinationPrefix.PrefixLength = (UINT8)msg->prefix_len;
     fwd_row->NextHop = sockaddr_inet(msg->family, &msg->gateway);
 
-    if (msg->iface.index != -1)
+    if (msg->iface.index != TUN_ADAPTER_INDEX_INVALID)
     {
         fwd_row->InterfaceIndex = msg->iface.index;
     }
@@ -1010,7 +1010,7 @@
  * if action = "set" then "static" is added before $addr
  */
 static DWORD
-netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr)
+netsh_wins_cmd(const wchar_t *action, DWORD if_index, const wchar_t *addr)
 {
     DWORD err = 0;
     int timeout = 30000; /* in msec */
@@ -1036,7 +1036,7 @@
     /* cmd template:
      * netsh interface ip $action wins $if_name $static $addr
      */
-    const wchar_t *fmt = L"netsh interface ip %ls wins %d %ls %ls";
+    const wchar_t *fmt = L"netsh interface ip %ls wins %lu %ls %ls";
 
     /* max cmdline length in wchars -- include room for worst case and some */
     size_t ncmdline = wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr)
@@ -2984,7 +2984,7 @@
          */
     }
 
-    int *if_index = malloc(sizeof(msg->iface.index));
+    PDWORD if_index = malloc(sizeof(msg->iface.index));
     if (if_index)
     {
         *if_index = msg->iface.index;
@@ -3017,7 +3017,7 @@
     /* cmd template:
      * netsh interface ipv4 set address name=$if_index source=dhcp
      */
-    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%d\" source=dhcp";
+    const wchar_t *fmt = L"netsh interface ipv4 set address name=\"%lu\" source=dhcp";
 
     /* max cmdline length in wchars -- include room for if index:
      * 10 chars for 32 bit int in decimal and +1 for NUL
@@ -3250,7 +3250,7 @@
                     break;
 
                 case undo_wins:
-                    netsh_wins_cmd(L"delete", *(int *)item->data, NULL);
+                    netsh_wins_cmd(L"delete", *(PDWORD)item->data, NULL);
                     break;
 
                 case wfp_block:

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1519?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38bb2d1fa66c543e8bcf47b7d77b6154d1895f81
Gerrit-Change-Number: 1519
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>